#!/usr/bin/env python
'''
DocIndexer HTML parser.
'''
from abstract_parser import AbstractParser
import formatter, htmllib
from common import EDocIndexer

class Parser(AbstractParser):

    description = 'HTML document parser'
    mime_types = ['text/html']

    class BodyWriter(formatter.NullWriter):
         def __init__(self):
             formatter.NullWriter.__init__(self)
             self._bodyText = []
         def send_flowing_data(self, str):
             self._bodyText.append(str)
         def bodytext(self):
             return ' '.join(self._bodyText)

    def text(self,filename):
        try:
            fmt = formatter.AbstractFormatter(self.BodyWriter())
            parser = htmllib.HTMLParser(fmt)
            parser.feed(open(filename).read())
            return self.unicode(parser.formatter.writer.bodytext())
        except:
            raise EDocIndexer,'unable to parse document'


if __name__ == '__main__':
    Parser.test()

# vim: ts=4 sw=4:
